namespace SmartSoft.Controls
{
    using SmartSoft;
    using System;
    using System.ComponentModel;
    using System.Windows.Forms;

    public class GBoxControl : GroupBox
    {
        private bool ib_OptionBox;

        protected override void OnCreateControl()
        {
            this.Font = AppInstance.SystemFont;
            base.OnCreateControl();
        }

        [DefaultValue(false)]
        public bool OptionBox
        {
            get
            {
                return this.ib_OptionBox;
            }
            set
            {
                this.ib_OptionBox = value;
            }
        }

        [DefaultValue(0)]
        public int Value
        {
            get
            {
                if (!this.OptionBox)
                {
                    return 0;
                }
                RadioButton button = null;
                int num = 0;
                foreach (Control control in base.Controls)
                {
                    if ((control is RadioButton) && (control as RadioButton).Checked)
                    {
                        button = control as RadioButton;
                        break;
                    }
                }
                if (button != null)
                {
                    foreach (Control control2 in base.Controls)
                    {
                        if ((control2 is RadioButton) && ((control2 as RadioButton).TabIndex < button.TabIndex))
                        {
                            num++;
                        }
                    }
                }
                return num;
            }
            set
            {
                if ((this.OptionBox && (base.Controls.Count > 0)) && ((value >= 0) && (value < base.Controls.Count)))
                {
                    RadioButton button = null;
                    int num = 0;
                    int tabIndex = base.Controls[0].TabIndex;
                    int num3 = 0;
                    foreach (Control control in base.Controls)
                    {
                        if ((control is RadioButton) && ((control as RadioButton).TabIndex < tabIndex))
                        {
                            button = control as RadioButton;
                            tabIndex = button.TabIndex;
                        }
                    }
                    while (num < value)
                    {
                        foreach (Control control2 in base.Controls)
                        {
                            if ((control2 is RadioButton) && ((control2 as RadioButton).TabIndex > tabIndex))
                            {
                                button = control2 as RadioButton;
                                num3 = button.TabIndex;
                                break;
                            }
                        }
                        foreach (Control control3 in base.Controls)
                        {
                            if (((control3 is RadioButton) && ((control3 as RadioButton).TabIndex > tabIndex)) && ((control3 as RadioButton).TabIndex < num3))
                            {
                                button = control3 as RadioButton;
                                num3 = button.TabIndex;
                            }
                        }
                        tabIndex = num3;
                        num++;
                    }
                    if (button != null)
                    {
                        button.Checked = true;
                    }
                }
            }
        }
    }
}

